<template>
  <div ref="dom" class="charts chart-pie"></div>
</template>

<script>
import echarts from 'echarts'
import tdTheme from './theme.json'
echarts.registerTheme('tdTheme', tdTheme)
export default {
  name: 'ChartCircle',
  props: {
    value: Array,
    text: String,
    subtext: String,
    colorLists:Array
  },
  mounted () {
    this.$nextTick(() => {
      let legend = this.value.map(_ => _.name)
      let option = {
        title: {
          text: this.text,
          subtext: this.subtext,
          x: 'center',
          y:'center',
           textStyle: {
	                    fontSize: '15',
	                    color:'red',
	                    fontWeight: 'normal'
	                }
        },
        tooltip: {
          trigger: 'item',
          formatter: "{d}%",
          show:false
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          data: legend,
             show:false
        },
        series: [
          {
                name:'车辆占比',
                type:'pie',
                selectedMode: 'single', 
		            radius: ['65%', '85%'],
		            avoidLabelOverlap: true,
		            hoverAnimation:false,
		            label: {
		                normal: {
		                    show: true,
                        position: 'center',
                          fontSize: '14',
                        //  formatter:function(val){   //让series 中的文字进行换行  
                        //         return val.name.split("-").join("\n");
                        //         }  
		                },
		                emphasis: {
		                    show: true
		                }
		            },
               labelLine: {
		                normal: {
		                    show: false
		                }
		            },
		            data:this.value
          }
        ],
      color:this.colorLists,
      }
      let dom = echarts.init(this.$refs.dom, 'tdTheme')
      dom.setOption(option)
    })
  }
}
</script>

<style lang="less">
.charts{
  //
}
</style>
